/**
 * Copyright(c)2012 Beijing PeaceMap Co.,Ltd.
 * All right reserved. 
 */
package com.pmc.dwa.security.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.pmc.dwa.security.utils.SpringSecurityUtils;

/**
 * @description 权限配置请求地址
 * @author aokunsang
 * @date 2013-1-6
 */
@Controller
public class SecurityController {

	/* 登录成功  */
	@RequestMapping(value="/mainDefault",method=RequestMethod.GET)
	public String defaultMain(){
		//复制浏览器地址直接进入[因为该地址没有加入权限验证链]
		if(SpringSecurityUtils.getCurrentUser()!=null && SpringSecurityUtils.getCurrentUser().getUserid()!=null){
			return "default";
		}else{
			return "redirect:/timeout";
		}
	}
	
	/* 登录超时*/
	@RequestMapping(value="/timeout")
	public void timeout(HttpServletResponse response,HttpServletRequest request) throws IOException{
		
		response.setContentType("text/html; charset=utf-8");
		response.setCharacterEncoding("utf-8");
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		response.getWriter().write("<script type=\"text/javascript\">top.location.href='"+basePath+"';</script>");
		response.getWriter().flush();
		response.getWriter().close();
	}
}
